package dao.impl;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import dao.OrderMasterDao;
import entity.Order_Master;
import util.C3P0Util;

public class OrderMasterDaoImpl implements OrderMasterDao{
	
	@Override
	public int addOrderMaster(Order_Master om) {
		QueryRunner qr = new QueryRunner(C3P0Util.getDataSource());
		String sql = "insert into order_master where order_sn = ? and user_id = ? and shipping_user = ?"
				+ "and address = ? and payment_method = '支付宝' and order_money = ? + shipping_money = ?"
				+ "and payment_money = ? and shipping_comp_name = ? and shipping_sn = ? and shipping_time=?"
				+ "and pay_time=?+ and receive_time = ? ";
		Object[] params = {om.getOrder_sn(),om.getUser_id(),om.getShipping_user(),om.getAddress(),om.getOrder_money()
				,om.getShipping_money(),om.getPayment_money(),om.getShipping_comp_name(),om.getShipping_sn(),
				new Date(),new Date(),new Date()};
		int i = 0;
		try {
			i = qr.update(sql, params);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return i;
	}

	@Override
	public List<Order_Master> getAllOrder_Master() {
		List<Order_Master> list = null;
		String sql = "select * from order_master";
		QueryRunner qr = new QueryRunner(C3P0Util.getDataSource());
		try {
			list = qr.query(sql, new BeanListHandler<Order_Master>(Order_Master.class));
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return list;
	}

}
